package heima3_2.cn.osc.base;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * Created by yaozhanlie on 2017/1/13.
 */


public class UserCollectAdapter extends FragmentPagerAdapter {
    //TODO:子类传进来
//    String[] mTitles = new String[]{"软件", "话题", "代码","博客","资讯"};  //这里直接用String数组写死了，一般是要传数据进来在设置


    public UserCollectAdapter(FragmentManager fm) {
        super(fm);
    }

    public UserCollectAdapter(FragmentManager fm, String[] mMTitles) {
        super(fm);
        this.mMTitles = mMTitles;
    }

    List<Fragment> mFragmentsList;
    public String[] mMTitles;

    //TODO:子类传进来
    public void setFragmentList(List<Fragment> fragmentList) {    //提供set方法让外界设置数据进来

        this.mFragmentsList = fragmentList;

    }

    @Override
    public CharSequence getPageTitle(int position) {    //tablayout的标题就是在这里设置的
        //这个是要自己写的，不然tabLayout会报空指针
        return mMTitles[position];
    }

    @Override
    public Fragment getItem(int position) {    //获得每个Pager的Fragment

        if (mFragmentsList != null) {
            return mFragmentsList.get(position);
        }
        return null;
    }

    @Override
    public int getCount() {    //获取ViewPager的个数

        return mFragmentsList == null ? 0 : mFragmentsList.size();
    }
}

